package Offer;

import java.util.Deque;
import java.util.LinkedList;

/**
 * 二叉树的镜像
 *
 * @author 是阿秋啊
 * @date 2022/04/05 22:03
 **/
public class Num27 {
    TreeNode sRoot;
    public TreeNode mirrorTree(TreeNode root) {
        if (root == null) {
            return null;
        }
        return helper(root, sRoot);
    }

    private TreeNode helper(TreeNode root, TreeNode sRoot) {
        if (root == null) {
            return null;
        }
        sRoot = root;
        TreeNode left = helper(root.right, sRoot.left);
        TreeNode right = helper(root.left, sRoot.right);
        sRoot.left = left;
        sRoot.right = right;
        return sRoot;
    }
}
